package com.qdu.dao;

import com.qdu.entity.Activity;
import com.qdu.util.DatabaseUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;


public class ManageActiDao {
    
    //删除活动-根据id
    public int DeleteActivity(String acitivityId){
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        int rows=0;
        
        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement("delete Activity where Aid=?");
            ps.setString(1,acitivityId);
            rows = ps.executeUpdate();
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }
        return rows;
    }
        
    
    
    //增加活动
    public int AddActivity(Activity a){
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        int rows=0;
        
        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement
            ("insert Activity(Aid,Auserid,Atype,Aname,Arank,Anumber,AdeadLine,Astatus,AstartTime,AendTime,Aaddress,Atransport,Anote,Acover) values('2',?,?,?,?,?,?,?,?,?,?,?,?,?)");
            ps.setString(1, a.getAuserId());
            ps.setString(2,a.getAtype());
            ps.setString(3,a.getAname());
            ps.setString(4,a.getArank());
            ps.setInt(5,a.getAnumber());
            ps.setString(6,a.getAdeadLine());
            ps.setString(7,a.getAstatus());
            ps.setString(8,a.getAstartTime());
            ps.setString(9,a.getAendTime());
            ps.setString(10,a.getAaddress());
            ps.setString(11,a.getAtransport());
            ps.setString(12,a.getAnote());
            ps.setString(13,a.getAcover());
            rows = ps.executeUpdate();
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }
        return rows;
    }
    
    //修改活动
    public int ModifyActivity(Activity acti,String ActivityId){
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        int rows=0;
        
        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement
            ("update Activity set Auserid=?,Atype=?,Aname=?,Arank=?,Anumber=?,AdeadLine=?,Astatus=?,AstartTime=?,AendTime=?,Aaddress=?,Atransport=?,Anote=? where Aid=?");
            ps.setString(1, acti.getAuserId());
            ps.setString(2,acti.getAtype());
            ps.setString(3,acti.getAname());
            ps.setString(4,acti.getArank());
            ps.setInt(5,acti.getAnumber());
            ps.setString(6,acti.getAdeadLine());
            ps.setString(7,acti.getAstatus());
            ps.setString(8,acti.getAstartTime());
            ps.setString(9,acti.getAendTime());
            ps.setString(10,acti.getAaddress());
            ps.setString(11,acti.getAtransport());
            ps.setString(12,acti.getAnote());
            ps.setString(13,ActivityId);
            rows = ps.executeUpdate();
            
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }
        return rows;
    }
    
    
}
